package com.zxx.good.config.exception;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
@Slf4j
public class GlobalException {

    /**
     * 全局异常捕捉处理
     */
    @ExceptionHandler(BusinessException.class)
    public Map<String, Object> apiExceptionHandler(BusinessException e) {

        Map<String, Object> errorResultMap = new HashMap<>(16);
        errorResultMap.put("code", e.getCode());
        errorResultMap.put("message", e.getMessage());

        return errorResultMap;
    }

}
